package tech.cn.note.html.tool;

import freemarker.template.Configuration;
import freemarker.template.Template;

import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

/**
 * .freemarker数据填充configuration重构
 * .根据configuration获取对应的template
 *
 * @author liuyong
 */
public class DocumentConfiguration extends Configuration {

    /**
     * 设置默认的参数值
     * @param templateDir
     * @throws Exception
     */
    public DocumentConfiguration(String templateDir) throws Exception{
        super(Configuration.VERSION_2_3_28);

        this.setDefaultEncoding(StandardCharsets.UTF_8.name());

        File tempFile = new File(templateDir);
        this.setDirectoryForTemplateLoading(tempFile);

        //默认设置模板更新等待时间5s
        this.setTemplateUpdateDelayMilliseconds(5000);
    }

    @Override
    public Template getTemplate(String name) throws IOException {
        return super.getTemplate(name,StandardCharsets.UTF_8.name());
    }
}
